<div class=" rc-pannel rc-pagepadding layui-form">
    <form class="layui-form" id="addform">
        <div class="rc-pannel-body">
            <div>
                <?php

                if (
                    count($contributecates) > 1 ||
                    (isset($contributecates[0]['children']) && count($contributecates[0]['children']) > 1)
                ) {
                ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label element_title">投稿站点：</label>
                        <div class="layui-input-block" style="line-height: 36px;">
                            <?php echo $siteinfo['title'] ?>

                        </div>

                    </div>


                    <div class="layui-form-item">
                        <label class="layui-form-label element_title">投稿栏目：</label>
                        <div class="layui-input-block" style="line-height: 36px;">
                            <?php
                            foreach ($ancestorCate as $acate) {
                            ?>
                                <?php echo $acate['title'] ?> /
                            <?php
                            }
                            ?>

                        </div>

                    </div>
                <?php
                }

                ?>


                <?php

                foreach ($fields as $field) {
                ?>
                    <div class="layui-form-item">
                        <label class="layui-form-label element_title"><?php echo $field['title'] ?>：</label>
                        <div class="layui-input-block">

                            <?php
                            $element = $field['element'];
                            unset($field['element']);
                            unset($field['id']);
                            $field['value'] = $field['default'];
                            echo element($element, ...$field);

                            ?>
                        </div>

                    </div>
                <?php
                }
                ?>
            </div>


        </div>

        <div class="rc-pannel-footer rc-pagepadding" style="text-align: center;">

            <div class="">
                <input type="hidden" name="cid" value="<?php echo request()->get('cid') ?>" />

                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-submit lay-filter="submit">投稿</button>
                <button type="reset" class="layui-btn layui-btn-sm">重置</button>
            </div>

        </div>
    </form>

</div>

<script type='text/javascript'>
    layui.use(function() {
        var $ = layui.jquery;
        var form = layui.form;
        var layCascader = layui.layCascader;



        form.on('submit(submit)', function(data) {

            $.ajax({
                url: '/app/cms/uc/Contribute/add?siteid=<?php echo request()->get('siteid') ?>', //请求路径
                type: "POST", //请求方式
                data: data.field, // 默认写法
                success: function(data) {
                    if (data.code == 0) {
                        toastr_success("添加成功", function() {
                            window.location.href = '/app/cms/uc/Contribute/index';
                        });
                    } else {
                        toastr_error(data.message);
                    }
                },
                error: function() {

                },

            });

            return false; // 阻止默认 form 跳转

        });
    });
</script>